import { reqGetUserAddressList, reqGetTradeInfoData } from "@/api";

const state = {
  tradeInfo: {},
};
const actions = {
  async getUserAddressList({ commit }) {
    const result = await reqGetUserAddressList();
    if (result.code === 200) {
      commit("SAVE_USER_ADDRESS_LIST", result.data);
    }
  },

  async getTradeInfoDate({ commit }) {
    const result = await reqGetTradeInfoData();
    if (result.code === 200) {
      commit("SAVE_TRADE_INFO_DATA", result.data);
    }
  },
};
const mutations = {
  SAVE_USER_ADDRESS_LIST(state, address) {
    state.userAddressList = address;
  },
  SAVE_TRADE_INFO_DATA(state, trade) {
    state.tradeInfo = trade;
  },
};
const getters = {
  // 1. 订单编号
  tradeNo(state) {
    return state.tradeInfo.tradeNo;
  },
  // 2. 商品数量
  totalNum(state) {
    return state.tradeInfo.totalNum;
  },
  // 3. 商品详细列表
  detailArrayList(state) {
    return state.tradeInfo.detailArrayList;
  },
  // 4. 总金额
  totalAmount(state) {
    return state.tradeInfo.totalAmount;
  },
};

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters,
};
